<template>
  <a-form :layout="'vertical'">
    <a-row v-for="(bo,index) in boList" :key="index">
      <a-col :span="12">
        <a-form-item :label="bo.name">
          <a-select @change="onSelectChange" v-model="boMdl[bo.key]" :getPopupContainer="p=>p.parentNode" :options="bo.template"></a-select>
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
</template>

<script>
  import FormPcApi from "@/api/form/core/formPc";
  import {RxInputButton,RxDialog,Dialog} from "@lowcode/jpaas-common-lib"
  export default {
    name: "FormPcPdfTemp1",
    props: ["boDefId"],
    components: {
      RxInputButton,
      RxDialog
    },
    data() {
      return {
        boMdl: {},
        boList: []
      }
    },
    created() {
      this.getTemplates(this.boDefId,'print');
    },
    methods: {
      onSelectChange(value) {
        this.$forceUpdate();
      },
      getTemplates(boDefId, type) {
        FormPcApi.getTemplatesByBoDef({boDefId: boDefId, type: type}).then(res => {
          this.boList = res;
          this.parseBoList();
        })
      },
      parseBoList() {
        for (var i = 0; i < this.boList.length; i++) {
          var bo = this.boList[i];
          this.boMdl[bo.key] = bo.template[0]['value'];
          this.boMdl[bo.key + '_check'] = true;
        }
      },
      getBoConfig(this_) {
        var boDefId= this_.boDefId;
        var templates = {main: {}, sub: {}};
        for (var i = 0; i < this_.boList.length; i++) {
          var bo = this_.boList[i];
          var type = bo.type;
          var template = this_.boMdl[bo.key];
          if (type == 'main') {
            templates[type][bo.key] = template;
          } else {
            if (this_.boMdl[bo.key + '_check']) {
              templates['sub'][bo.key] = template;
            }
          }
        }
        return {boDefId: boDefId, templates: JSON.stringify(templates)};
       }
      }
  }
</script>

<style scoped>

</style>